﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LoU.Dungeons
{
    public class RatioGain
    {
        public double CCUsage { get; set; }
        public int Ratio { get; set; }
        public MilitaryBuild Build { get; set; }
        public Resources Balance { get; set; }
        public double RoundTripTime { get; set; }
        public double MaxReplacableTSWithinRountripTime { get; set; }

        public double BalancePerTS { get { return Math.Round(this.Balance.Total, 2); } }

        private double MaxReplaceableTS { get { return this.Build == null ? 0 : Math.Min(this.MaxReplacableTSWithinRountripTime, this.Build.MaxTS); } }

        public string MaxReplaceableTSView { get { return Math.Round(this.MaxReplaceableTS / 1000.0) + "k"; } }

        public double TotalWithoutGoldPerTS
        {
            get
            {
                return this.Build == null || this.Balance == null ? 0 :
                    Math.Round(this.Balance.TotalWithoutGold, 2);
            }
        }

        public double TotalWithoutGoldPerHour
        {
            get
            {
                return this.Build == null || this.Balance == null ? 0 :
                    Math.Round(this.Balance.TotalWithoutGold * this.MaxReplaceableTS / this.RoundTripTime / 1000.0, 2);
            }
        }

        private double balancePerHour(ResourceType res)
        {
            return this.Build == null || this.Balance == null ? 0 :
                    Math.Round(this.Balance[res] * this.MaxReplaceableTS / this.RoundTripTime / 1000.0, 2);
        }

        public double FoodPerHour
        {
            get
            {
                return balancePerHour(ResourceType.Food);
            }
        }

        public double IronPerHour
        {
            get
            {
                return balancePerHour(ResourceType.Iron);
            }
        }

        public double WoodPerHour
        {
            get
            {
                return balancePerHour(ResourceType.Wood);
            }
        }

        public double StonePerHour
        {
            get
            {
                return balancePerHour(ResourceType.Stone);
            }
        }

        public double GoldPerHour
        {
            get
            {
                return balancePerHour(ResourceType.Gold);
            }
        }
    }
}
